package com.rocky.project.action.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.opensymphony.webwork.ServletActionContext;
import com.rocky.project.action.base.BaseAction;

public class DownloadAction extends BaseAction {
	
	private static final long serialVersionUID = -8594184834633165967L;
	private InputStream inputStream;
	private String contentType;
	private String filePath;
	private String fileName;
	private String contentDisposition;
	private String contentLength;
	private File file;
	

	
	public String download() throws Exception{
		
		file = new File(ServletActionContext.getServletContext().getRealPath(filePath));/**//* * 打开下载的文件     */
		inputStream = new FileInputStream(file);
		//fileName= "指定的文件名"; /**//* 这里必须要带后缀*/
		contentDisposition ="attachment;filename="+fileName+"";//提示保存的文件名
		contentType="application/x-msdownload;charset=utf-8";/**//* * 设定下载属性   application/octet-stream application/x-msdownload */
		contentLength = String.valueOf(file.length());
		return "download"; /**//* 程序段END*/

	}
	public String getContentType() {
		return contentType;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public InputStream getInputStream() {
		return inputStream;
	}
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	public String getContentDisposition() {
		return contentDisposition;
	}
	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}
	public String getContentLength() {
		return contentLength;
	}
	public void setContentLength(String contentLength) {
		this.contentLength = contentLength;
	}
	
}
